package com.fengzuxiao.weatherdemo.lr;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.fengzuxiao.weatherdemo.R;
import com.fengzuxiao.weatherdemo.User;
import com.fengzuxiao.weatherdemo.UserService;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by 17929 on 2020/6/9.
 */

public class RegistActivity extends AppCompatActivity{
    private Button regist_b;
    private EditText regist_e;
    private EditText regist_e2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);
        init();
    }

    private void init() {
        regist_b = findViewById(R.id.regist_b);
        regist_e = findViewById(R.id.regist_e);
        regist_e2 = findViewById(R.id.regist_e2);
    }
    public void onClick(View view) {
        String str = regist_e.getText().toString().trim();
        String str1 = regist_e2.getText().toString().trim();
        UserService uService = new UserService(this);
        User user = new User();
        user.setUsername(str);
        user.setPassword(str1);

        boolean fals = uService.register(user);

        if (TextUtils.isEmpty(str) && TextUtils.isEmpty(str1)) {
            Toast.makeText(this, "账号或密码不能为空", Toast.LENGTH_SHORT).show();
        } else if (fals) {
            onBackPressed();
            Toast.makeText(this, "注册成功", Toast.LENGTH_LONG).show();
        } else {

            Toast.makeText(this, "账号已被注册", Toast.LENGTH_SHORT).show();
        }

    }
}
